package cn.touna.jss.modules.custom.batch;

public class BatchCounter {
    private int readCount;
    private int writeCount;
    private boolean readComplete = false;
    private boolean writeComplete = false;

    public synchronized void incrementReadCount(){
        readCount++;
    }

    public synchronized void incrementWriteCount(){
        writeCount++;
    }

    public void setReadComplete(boolean readComplete) {
        this.readComplete = readComplete;
    }

    public int getReadCount() {
        return readCount;
    }

    public int getWriteCount() {
        return writeCount;
    }

    public boolean isReadComplete() {
        return readComplete;
    }

    public synchronized boolean checkWriteComplete(){
        return readComplete && readCount == writeCount;
    }

    public boolean isWriteComplete() {
        return writeComplete;
    }

    public void setWriteComplete(boolean writeComplete) {
        this.writeComplete = writeComplete;
    }

    @Override
    public String toString() {
        return "BatchCounter{" +
                "readCount=" + readCount +
                ", writeCount=" + writeCount +
                ", readComplete=" + readComplete +
                ", writeComplete=" + writeComplete +
                '}';
    }
}
